import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Jiang Jinxi
 * Date: 2024-03-30
 * Time: 15:51
 */
public class Test3 {
    public static int ouShuSum(long number){
        String str = number+"";
        int sum = 0;
        for (int i = str.length()-2; i >= 0 ; i-=2) {
            char n = str.charAt(i);
            int t = (n - '0')*2;
            if(t > 9){
                sum += t/10+t%10;
                continue;
            }
            sum += t;
        }
        return sum;
    }
    public static int jiShuNum(long number){
        String str = number+"";
        int sum = 0;
        for (int i = str.length()-1; i >= 0 ; i-=2) {
            int n = str.charAt(i) - '0';
            sum += n;
        }
        return sum;

    }


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long number = scanner.nextLong();
        int sum = jiShuNum(number) + ouShuSum(number);
        if(sum % 10 == 0){
            System.out.println("合法");
        }else{
            System.out.println("不合法");
        }
    }
}
